
public class MyDate {
	private int year;
	private int month;
	private int day;
	private String[] strMonths={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sup","Oct","Nov","Dec"};
	private String[] strDays={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
	private int[] daysInMonths={31,28,31,30,31,30,31,31,30,31,30,31};
	public boolean isLeapYear(int year){
		if(year%4==0&&year%100!=0||year%400==0){
			return true;
		}else return false;
	}
	public boolean isValidDate(int year,int month,int day){
		if(isLeapYear(year)&&month==2&&day==29)return true;
		if(month>=1&&month<=12){
			if(day>=1&&day<=daysInMonths[month-1]){
				return true;
			}
		}return false;
	}
	public int getDayOfWeek(int year,int month,int day){
		int a;
		int b=0;
		int c=0;
		for(int i=1970;i<year;i++){
			if(isLeapYear(i)){
				b++;
			}
		}
		for(int i=0;i<month-1;i++){
			c=c+daysInMonths[i];
		}
		if(isLeapYear(year)&&month>2){
			c++;
		}
		a=(year-1970)*365+b+c+day;
		return a%7+3;
	}
	public MyDate() {
		
	}
	public MyDate(int year, int month, int day) {
		super();
		this.year = year;
		this.month = month;
		this.day = day;
	}
	public int getYear() {
		return year;
	}
	public int getMonth() {
		return month;
	}
	public int getDay() {
		return day;
	}
	public void setYear(int year) {
		this.year = year;
	}
	public void setMouth(int month) {
		this.month = month;
	}
	public void setDay(int day) {
		this.day = day;
	}
	@Override
	public String toString() {
		return "MyDate [year=" + year + ", month=" + month + ", day=" + day + "]";
	}
	public MyDate nextDay(){
//		if(day==28&&month==2&&isLeapYear(year)){
//			this.day=29;
//			this.month=2;
//			return this;
//		}
		this.day++;
		
		if(!isValidDate(this.year,this.month,this.day)){
			month++;
			this.day=1;
			
		}
		if(!isValidDate(this.year,this.month,this.day)){
			year++;
			this.month=1;
		}
		
		return this;
	}
	public MyDate nextMonth(){
		this.month++;
		if(!isValidDate(this.year,this.month,this.day)){
			year++;
			this.month=1;
		}
		return this;
	}
	public MyDate nextYear(){
		this.year++;
		return this;
	}
	public MyDate previousDay(){
		this.day--;
		if(!isValidDate(this.year,this.month,this.day)){
			month--;
			if((isLeapYear(year)&&month==2&&day==0)){
				this.day=29;
			}
			else{
				if(month==0){
					month=12;
					year--;
				}
				this.day=daysInMonths[month-1];
			}
			
		}
		
		return this;
	}
	public MyDate previousMonth(){
		this.month--;
		if(!isValidDate(this.year,this.month,this.day)){
			year--;
			this.month=12;
		}
		return this;
	}
	public MyDate previousYear(){
		this.year--;
		return this;
	}
}
